package com.jxtti.service;

import org.apache.log4j.Logger;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.jxtti.dao.ArticleListDao;
import com.jxtti.dao.SubjectMsgDao;
import com.jxtti.entity.SubjectMsg;
/**
 * 
 * <br>
 * <b>功能：</b>SubjectMsgService<br>
 * <b>作者：lwb</b><br>
 * <b>日期：</b> Nov 26, 2015 <br>
 * <b>版权所有：<b>版权所有(C) 2015，<br>
 */
@Service("subjectMsgService")
@Transactional(rollbackFor = { RuntimeException.class, Exception.class })
public class SubjectMsgService {

	private final static Logger log= Logger.getLogger(SubjectMsgService.class);
	

	

	@Autowired
    private SubjectMsgDao subjectMsgDao;
	@Autowired
	private ArticleListDao articleListDao;


	/**
	 * 获取信息数据列表
	 * 
	 * @param data
	 * @return
	 */
	public Map<String, Object> list(Map<String, Object> data,  SubjectMsg subjectMsg)
	{
		
		int pageNum = Integer.parseInt((data.get("currentPage") == null || data
				.get("currentPage").equals("0")) ? "1" : data.get("currentPage").toString());
		// 每页显示条数 
		int pageSize = Integer.parseInt((data.get("pageSize") == null || data.get("pageSize").equals("0")) ? "10" : data.get("pageSize").toString());
		PageHelper.startPage(pageNum, pageSize);
		PageInfo<SubjectMsg> pages = new PageInfo<SubjectMsg>( subjectMsgDao.queryByList(data));
		data.put("page", pages);
		return data;
	}
	
	
	public  PageInfo<SubjectMsg> listPage(Map<String, Object> data)
	{
		//如果是污染源专题   行政处罚.
		//第几页
		int pageNum = Integer.parseInt((data.get("currPageNum") == null || data.get("currPageNum").equals("0")) ? "1" : data.get("currPageNum").toString());
		// 每页显示条数 
		int pageSize = Integer.parseInt((data.get("pageRowSize") == null || data.get("pageRowSize").equals("0")) ? "10" : data.get("pageRowSize").toString());
		
		PageHelper.startPage(pageNum, pageSize);			
		PageInfo<SubjectMsg> pages = new PageInfo<SubjectMsg>(subjectMsgDao.listPage(data));	
		return pages;
	}
	
	
	
	/**
	 * 查询所有数据。 
	 * @param data
	 * @return
	 */
	public List<SubjectMsg>  queryAll(Map<String, Object> data)
	{
		return  subjectMsgDao.queryByList(data);
	}
	
	public List<SubjectMsg>  loadSubjectMsgTitle(Map<String, Object> data)
	{
		return  subjectMsgDao.loadSubjectMsgTitle(data);
	}
	
	
	
	public List<SubjectMsg>  loadSubjectMsgByFlag(Map<String, Object> data)
	{
		return  subjectMsgDao.loadSubjectMsgByFlag(data);
	}
	
	
	public List<SubjectMsg>  queryArticleByTop(Map<String, Object> data)
	{
		return  subjectMsgDao.queryArticleByTop(data);
	}
	
	public List<SubjectMsg>  listDataWithoutContent(Map<String, Object> data)
	{
		return  subjectMsgDao.listDataWithoutContent(data);
	}
	/**
	 * 添加数据.
	 * 
	 * @param data
	 * @return
	 */
	public int add(SubjectMsg subjectMsg)
	{
		int insertCount = subjectMsgDao.add(subjectMsg);
		return insertCount;
	}
	

	/**
	 * 修改数据.
	 * 
	 * @param data
	 * @return
	 */
	public int update(SubjectMsg subjectMsg)
	{
		int updateCount = subjectMsgDao.update(subjectMsg);
		return updateCount;
	}
	

	/**
	 * 删除数据.
	 * 
	 * @param data
	 * @return
	 */
	public int delete(SubjectMsg subjectMsg)
	{
		int deleteCount = subjectMsgDao
				.delete(subjectMsg);
		
		return deleteCount;
	}
	
	
	public SubjectMsg querySubjectMsgById(SubjectMsg subjectMsg)
	{
		subjectMsg = subjectMsgDao.querySubjectMsgById(subjectMsg);
		return subjectMsg;
	}

}
